# Maintainer: Daurnimator <daurnimator@archlinux.org>

pkgname=(lua-luaossl lua51-luaossl lua52-luaossl lua53-luaossl)
pkgver=20220711
pkgrel=2
pkgdesc='Most comprehensive OpenSSL module in the Lua universe'
arch=('loong64' 'x86_64')
url='http://25thandclement.com/~william/projects/luaossl.html'
license=('MIT')
makedepends=('luarocks' 'lua' 'lua51' 'lua52' 'lua53')
depends=('openssl')
source=("$pkgname-$pkgver.tar.gz::https://github.com/wahern/luaossl/archive/rel-$pkgver.tar.gz"
      "https://github.com/wahern/luaossl/releases/download/rel-20220711/luaossl-$pkgver-0.rockspec")
sha256sums=('f16c4cd2c880f270c1c73daa0a4bfdd11ae3155b92a2086863731e06d241300b'
            '1ec15fc11183ca911af98c50472ac1e9693f8148e7065656a5f1a0f2dd9ec82c')

build() {
  cd "luaossl-rel-$pkgver"
  for v in 5.1 5.2 5.3 5.4; do
    mkdir -p "$v/"
    luarocks make --pack-binary-rock --lua-version="$v" --deps-mode=none \
      CFLAGS="$CPPFLAGS $CFLAGS -fPIC" \
      LIBFLAG="$LDFLAGS -shared" \
      ../luaossl-"$pkgver"-0.rockspec
    mv luaossl-"$pkgver"-0.*.rock "$v/"
  done
}

package_lua-luaossl() {
  pkgdesc="$pkgdesc for Lua 5.4"

  cd "luaossl-rel-$pkgver"
  luarocks install --lua-version=5.4 --tree="$pkgdir/usr/" --deps-mode=none 5.4/*.rock --no-manifest
  install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

package_lua51-luaossl() {
  pkgdesc="$pkgdesc for Lua 5.1"

  cd "luaossl-rel-$pkgver"
  luarocks install --lua-version=5.1 --tree="$pkgdir/usr/" --deps-mode=none 5.1/*.rock --no-manifest
  install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

package_lua52-luaossl() {
  pkgdesc="$pkgdesc for Lua 5.2"

  cd "luaossl-rel-$pkgver"
  luarocks install --lua-version=5.2 --tree="$pkgdir/usr/" --deps-mode=none 5.2/*.rock --no-manifest
  install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

package_lua53-luaossl() {
  pkgdesc="$pkgdesc for Lua 5.3"

  cd "luaossl-rel-$pkgver"
  luarocks install --lua-version=5.3 --tree="$pkgdir/usr/" --deps-mode=none 5.3/*.rock --no-manifest
  install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
